<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>index.js</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        
        <h1>
            index.js
        </h1>
        <ul class="files">
            
            <li>
                lib/assets/javascripts/sale_app/custom_products/index.js
                
            </li>
            <li>Last modified: 2017-02-10 16:58:03 +0800</li>
        </ul>
    </div>

    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>jQuery(function($){</p>

<pre><code>//点击删除按钮，删除
$(&quot;a.js-to-remove-my-product&quot;).on(&quot;click&quot;, function(){
  var _this = this
  BootstrapDialog.confirm(&#39;确定移除该商品吗？&#39;, function(result){
          if(result) {
            var id = $(_this).data(&quot;id&quot;);
            var csrf = $(&quot;input#js-sale-custom-product-index&quot;).val();
              $.ajax({
                url: &quot;/api/custom_products/&quot;+ id +&quot;/unuse&quot;,
                method: &#39;put&#39;,
                headers: {
                  &#39;X-CSRF-Token&#39;: csrf
                },
                success: function(data){
                  if (data.status){
                    $(_this).parent().parent().remove();
                  }
                }
              })
          }else {

          }
      });
})

//点击编辑按钮，使用js是防止在循环多次调用store_id。
$(&quot;a.js-to-edit-my-custom&quot;).on(&quot;click&quot;, function(e){
  e.preventDefault();
  var id = $(this).data(&quot;id&quot;);
  var storeId = getUrlParam(&quot;store_id&quot;);
  location.href=&quot;/sales/custom_products/&quot;+ id +&quot;/edit?store_id=&quot;+storeId
})

// add my product to cart items
$(&quot;a.js-add-my-custom-to-items&quot;).on(&quot;click&quot;, function(e){
  e.preventDefault();
  var _this = this
  BootstrapDialog.show({
          title: &#39;提示：&#39;,
          message: &quot;请输入数量: &lt;input type=&#39;text&#39; name=&#39;quantity&#39; value=&#39;&#39; placeholder=&#39;添加到购物车的数量&#39; class=&#39;js-add-items-dialog-quantity&#39;&gt;&quot;,
          cssClass: &#39;add-to-items-dialog&#39;,
          buttons: [
            {
              label: &#39;取消&#39;,
              cssClass: &#39;&#39;,
              action: function(dialog){
                  dialog.close();
              }
            },
            {
                label: &#39;确定&#39;,
                cssClass: &#39;btn-primary&#39;,
                action: function(dialog){
                    var id = $(_this).data(&quot;id&quot;);
                    var storeId = getUrlParam(&quot;store_id&quot;);
                    var quantity = $(&quot;input.js-add-items-dialog-quantity&quot;).val();
                    var csrf = $(&quot;input#js-sale-custom-product-index&quot;).val();
                                              $.ajax({
                                                      url: &quot;/api/cart_items&quot;,
                                                      method: &quot;post&quot;,
                                                      headers: {
                                &#39;X-CSRF-Token&#39;: csrf
                              },
                                                      data: {store_id: storeId, store_product_id: id, quantity: quantity},
                                                      success: function(data){
                                                              if(data.status == true){
                          showErrorView(&quot;已经成功加入购物车&quot;);
                          dialog.close();
                                                              }else {
                          dialog.close();
                                                                      showErrorView(data.message);
                                                              }
                                                      }
                                              })
                }
            }
        ]
      });
})
// end add my product to items in index</code></pre>

<p>})</p>

    </div>
  


  


  
  


  


  

  



  

    

    

    


    


    <!-- Methods -->
              </div>

    </div>
  </body>
</html>
